# -*- coding: utf-8 -*-
'''
Description: 
version: 1.0.0
Author: peng2.zhang
Date: 2020-11-23 17:22:32
LastEditors: peng2.zhang
LastEditTime: 2021-05-14 10:21:22
'''

from collections import namedtuple
from tornado.util import ObjectDict
from code import interact

error = namedtuple("operate", ["errvalue", "errcode"])


class ERROR(object):
    system_err = error(errcode=-999999, errvalue=u"系统错误")
    captcha_err = error(errcode=-999409, errvalue=u"验证码错误")
    captcha_empty_err = error(errcode=-999508, errvalue=u"验证码不能为空")
    captcha_expired_err = error(errcode=-999507, errvalue=u"验证码已过期，请刷新重试")
    params_err = error(errcode=-999506, errvalue=u"参数错误")
    params_empty_err = error(errcode=-999505, errvalue=u"参数不能为空")
    params_validate_err = error(errcode=-999504, errvalue=u"参数校验错误")
    not_found_err = error(errcode=-999404, errvalue=u"对不起！您正在访问的数据资源未找到")
    xsrf_err = error(errcode=-999403, errvalue=u"缺少xsrf参数，禁止提交表单")
    database_save_err = error(errcode=-999402, errvalue=u"数据库保存错误")
    database_get_err = error(errcode=-999401, errvalue=u"数据库获取错误")
    # 注册和登录
    username_empty_err      = error(errcode=-100001, errvalue=u"用户名不能为空")
    username_duplicate_err  = error(errcode=-100017, errvalue=u"该用户名已经被使用")
    username_err            = error(errcode=-100002, errvalue=u"该用户名不存在")
    password_empty_err      = error(errcode=-100003, errvalue=u"密码不能为空")
    password_err            = error(errcode=-100004, errvalue=u"密码错误")
    email_empty_err         = error(errcode=-100005, errvalue=u"邮箱不能为空")
    email_format_err        = error(errcode=-100015, errvalue=u"邮箱格式错误")
    email_duplicate_err     = error(errcode=-100016, errvalue=u"该邮箱已经被使用")
    email_err               = error(errcode=-100006, errvalue=u"邮箱错误")
    mobile_empty_err        = error(errcode=-100007, errvalue=u"手机号不能为空")
    mobile_duplicate_err    = error(errcode=-100018, errvalue=u"该手机号已经被使用")
    mobile_format_err       = error(errcode=-100019, errvalue=u"手机号格式不正确")
    mobile_err              = error(errcode=-100008, errvalue=u"手机号错误")
    user_empty_err          = error(errcode=-100009, errvalue=u"操作用户不能为空")
    checker_empty_err       = error(errcode=-100010, errvalue=u"审核用户不能为空")
    old_password_empty_err  = error(errcode=-100011, errvalue=u"旧密码不能为空")
    new_password_empty_err  = error(errcode=-100012, errvalue=u"新密码不能为空")
    repeat_password_empty_err = error(errcode=-100013, errvalue=u"重复密码不能为空")
    repeat_password_err     = error(errcode=-100014, errvalue=u"重复密码与新密码不一致")
    # sql_history
    sql_history_exec_status_err     = error(errcode=-100100, errvalue=u"sql已执行，不会重复执行")


ERR = ObjectDict()
for attr in dir(ERROR):
    err = getattr(ERROR, attr)
    if isinstance(err, error):
        setattr(ERR, attr.upper(), err.errcode)
        setattr(ERR, str(err.errcode), err.errvalue)

if __name__ == '__main__':
    # interact(local=locals())
    print(ERROR.username_err)
